import '../../../utils/json_converter.dart';

class Book {
  int? id;                       // 图书ID
  int? storeId;                  // 店铺ID
  int? storeBookId;              // 店铺图书ID
  String? isbn;                  // 国际标准书号
  String? name;                  // 图书名称
  String? imageUrl;              // 图书封面图片URL
  String? author;                // 作者
  String? keyword;               // 关键词，如"古典文学,中国文学,名著"
  String? publisher;             // 出版社
  double? referencePrice;        // 参考价格
  double? purchasePrice;         // 进货价格
  double? salePrice;             // 销售价格
  double? discountPrice;         // 折扣价格
  int? inventory;                // 库存数量
  String? createTime;            // 创建时间
  String? updateTime;            // 更新时间
  String? createUserString;      // 创建用户信息
  int? categoryId;               // 图书分类ID
  bool? isDeleted;               // 是否已删除

  Book({
    this.id,
    this.storeId,
    this.storeBookId,
    this.isbn,
    this.name,
    this.imageUrl,
    this.author,
    this.keyword,
    this.publisher,
    this.referencePrice,
    this.purchasePrice,
    this.salePrice,
    this.discountPrice,
    this.inventory,
    this.createTime,
    this.updateTime,
    this.createUserString,
    this.categoryId,
    this.isDeleted,
  });

  Book.fromJson(Map<String, dynamic> json) {
    id = JsonConverter.toInt(json['id']);
    storeId = JsonConverter.toInt(json['storeId']);
    storeBookId = JsonConverter.toInt(json['storeBookId']);
    isbn = JsonConverter.toStr(json['isbn']);
    name = JsonConverter.toStr(json['name']);
    imageUrl = JsonConverter.toStr(json['imageUrl']);
    author = JsonConverter.toStr(json['author']);
    keyword = JsonConverter.toStr(json['keyword']);
    publisher = JsonConverter.toStr(json['publisher']);
    referencePrice = JsonConverter.toDouble(json['referencePrice']);
    purchasePrice = JsonConverter.toDouble(json['purchasePrice']);
    salePrice = JsonConverter.toDouble(json['salePrice']);
    discountPrice = JsonConverter.toDouble(json['discountPrice']);
    inventory = JsonConverter.toInt(json['inventory']);
    createTime = JsonConverter.toStr(json['createTime']);
    updateTime = JsonConverter.toStr(json['updateTime']);
    createUserString = JsonConverter.toStr(json['createUserString']);
    categoryId = JsonConverter.toInt(json['categoryId']);
    isDeleted = JsonConverter.toBool(json['isDeleted']);
  }

  Map<String, dynamic> toJson() {
    final data = <String, dynamic>{};
    data['id'] = id;
    data['storeId'] = storeId;
    data['storeBookId'] = storeBookId;
    data['isbn'] = isbn;
    data['name'] = name;
    data['imageUrl'] = imageUrl;
    data['author'] = author;
    data['keyword'] = keyword;
    data['publisher'] = publisher;
    data['referencePrice'] = referencePrice;
    data['purchasePrice'] = purchasePrice;
    data['salePrice'] = salePrice;
    data['discountPrice'] = discountPrice;
    data['inventory'] = inventory;
    data['createTime'] = createTime;
    data['updateTime'] = updateTime;
    data['createUserString'] = createUserString;
    data['categoryId'] = categoryId;
    data['isDeleted'] = isDeleted;
    return data;
  }
}
